﻿/*
 * Copyright © 2011 Tristan Reeves, treeves@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Linq;

namespace Sprinkles.Attributes
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class ExportAttribute : Attribute
    {
        private bool m_IsLazyInit;
        private bool m_IsDefaultForThisType = true;
        private readonly Type[] m_DefaultForTypes;
        private readonly string m_Name;
        private bool m_IsSingleton = true;
        private Scope m_Scope = Scope.None;

        public ExportAttribute(params Type[] defaultForTypes)
            : this((string)null, defaultForTypes)
        {
        }
        public ExportAttribute(string name, params Type[] defaultForTypes)
        {
            m_Name = name;

            m_DefaultForTypes = (defaultForTypes ?? new Type[0])
                .Where(x => x != null)
                .Distinct()
                .ToArray();
        }
        public string Name
        {
            get { return m_Name; }
        }
        public Scope Scope
        {
            get { return m_Scope; }
            set { m_Scope = value; }
        }
        public bool IsDefaultForThisType
        {
            get { return m_IsDefaultForThisType; }
            set { m_IsDefaultForThisType = value; }
        }
        public bool IsSingleton
        {
            get { return m_IsSingleton; }
            set { m_IsSingleton = value; }
        }
        public bool IsLazyInit
        {
            get { return m_IsLazyInit; }
            set { m_IsLazyInit = value; }
        }

        public Type[] DefaultForTypes
        {
            get { return m_DefaultForTypes ?? new Type[0]; }
        }
    }
}
